package com.zlt.service.impl;

import com.zlt.dao.Impl.QuestionDaoImpl;
import com.zlt.dao.QuestionDao;
import com.zlt.entity.Question;
import com.zlt.entity.User;
import com.zlt.service.QuestionService;
import com.zlt.util.ActiveUserUtil;
import com.zlt.util.StringUtil;
import com.zlt.vo.ActiveUser;

import java.util.Date;

public class QuestionServiceImpl implements QuestionService {

    private QuestionDao questionDao=new QuestionDaoImpl();

    //private ActiveUser activeUser=new ActiveUser();


    @Override
    public boolean addQuestion(String yourworks) {
        Question question = new Question();
        question.setContent(yourworks);
        question.setCreateTime(StringUtil.getCurrentTime());
        question.setState(0);

        ActiveUser activeUser = ActiveUserUtil.get();
        if (activeUser == null) {
            throw new RuntimeException("当前未登录");
        }
        User user = new User();
        user.setUid(activeUser.getUid());
        question.setUser(user);
        return questionDao.addQuestion(question) > 0;
    }




    @Override
    public boolean insertQuestion(String yourworks) {
        Question question = new Question();
        question.setContent(yourworks);
        question.setCreateTime(StringUtil.getCurrentTime());
        question.setState(1);

        ActiveUser activeUser = ActiveUserUtil.get();
        if (activeUser == null) {
            throw new RuntimeException("当前未登录");
        }

        User user = new User();
        user.setUid(activeUser.getUid());
        question.setUser(user);
        return questionDao.insertQuestion(question) > 0;
    }


}
